package com.come4loves.game.module.card.model;

import java.util.List;

import com.come4loves.core.utils.Splitable;
import com.come4loves.core.utils.StringUtils;
import com.come4loves.game.module.battle.helper.PBConvertHelper;
import com.come4loves.game.module.card.constant.CardType;
import com.come4loves.game.proto.CardProto;

/**
 * 存储对象，把每张卡片看做一个对象。
 * @author 8wy00
 *
 */
public class CardModel {
	
	
	public int cfgId;
	
	
	public int level;
	
	/**
	 * 卡片类型 
	 * @see CardType
	 */
	public CardType type;
	
	
	public int count;
	
	/**
	 * 卡牌默认出手速度
	 */
	public int priority;
	
	
	public static CardModel valueOf(String params) {
		CardModel cardModel = new CardModel();
		if (StringUtils.isNotBlank(params)) {
			List<Integer> valueInts = StringUtils.delimiterString2IntList(params, Splitable.BETWEEN_DOT);
			cardModel.cfgId = valueInts.get(0);
			cardModel.level = valueInts.get(1);
			cardModel.type = CardType.geCardType(valueInts.get(2));
			cardModel.count = valueInts.get(3);
			cardModel.priority = valueInts.get(4);
		}
		return cardModel;
	}
	
	
	@Override
	public String toString() {
		StringBuffer sBuffer = new StringBuffer();
		sBuffer.append(cfgId).append(Splitable.BETWEEN_DOT);
		sBuffer.append(level).append(Splitable.BETWEEN_DOT);
		sBuffer.append(type.ordinal()).append(Splitable.BETWEEN_DOT);
		sBuffer.append(count).append(Splitable.BETWEEN_DOT);
		sBuffer.append(priority);
		return sBuffer.toString();
	}
	
	
	/**
	 * 
	 * @param cfgId
	 * @param level
	 * @param typeCode
	 * @param count
	 * @return
	 */
	public static CardModel valueOf(int cfgId, int level, CardType type, int count, int priority) {
		CardModel cardModel = new CardModel();
		cardModel.cfgId = cfgId;
		cardModel.level = level;
		cardModel.type = type;
		cardModel.count = count;
		cardModel.priority = priority;
		return cardModel;
	}
	
	
	public static CardProto.CardModel convert(CardModel model) {
		CardProto.CardModel.Builder cardModel = CardProto.CardModel.newBuilder();
		cardModel.setCfgId(model.cfgId);
		cardModel.setLevel(model.level);
		cardModel.setType(PBConvertHelper.cardTypeConvert(model.type));
		cardModel.setCount(model.count);
		cardModel.setPriority(model.priority);
		return cardModel.build();
	}
	
}
